package com.wzdigit.wms.wms.controller.inventory;

import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.request.report.*;
import com.wzdigit.wms.basic.client.response.report.*;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.core.inventory.GoodsSnReportService;
import com.wzdigit.wms.wms.service.core.inventory.LotInvReportService;
import com.wzdigit.wms.wms.service.core.inventory.OrderBlotterReportService;
import com.wzdigit.wms.wms.service.core.inventory.SaleInvReportService;
import com.wzdigit.wms.wms.service.report.MaterialPeakService;
import com.wzdigit.wms.wms.service.report.WarehousePeakService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存报表
 * Created by zyf on 2021/4/22 11:47
 */
@RestController
@Api(tags = "库存报表")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class InvReportController {
    /*日志工具*/
    private final Logger logger = LoggerFactory.getLogger(Object.class);

    private final String REQUEST_MODEL = "/Inventory";

    @Autowired
    private SaleInvReportService saleInvReportService;

    @Autowired
    private LotInvReportService lotInvReportService;

    @Autowired
    private OrderBlotterReportService orderBlotterReportService;

    @Autowired
    private GoodsSnReportService goodsSnReportService;

    @Autowired
    private MaterialPeakService materialPeakService;

    @Autowired
    private WarehousePeakService warehousePeakService;

    @ApiOperation(value = "获取整机外销库存（分页）", notes = "获取整机库存外销（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/SaleInv", method = RequestMethod.GET)
    public PagerInfo<List<SaleInvReportReponse>> searchSaleInvReport(
            SaleInvReportSearchRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return saleInvReportService.searchSaleInvReportNew(search,pager);
            //return saleInvReportService.searchSaleInvReport(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出整机外销库存", notes = "导出整机库存外销")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportSaleInv", method = RequestMethod.GET)
    public void exportSaleInvReport(
            SaleInvReportSearchRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            saleInvReportService.exportSaleInvReportNew(search,servletRequest,servletResponse);
            //saleInvReportService.exportSaleInvReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "获取整机库位库存（分页）", notes = "获取整机库位库存（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/LotInv", method = RequestMethod.GET)
    public PagerInfo<List<LotInvReportReponse>> searchLotInvReport(
            LotInvReportSearchRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return lotInvReportService.searchSaleInvReportNew(search,pager);
            //return lotInvReportService.searchSaleInvReport(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出整机仓位库存", notes = "导出整机仓位库存")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportLotInv", method = RequestMethod.GET)
    public void exportLotInvReport(
            LotInvReportSearchRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            lotInvReportService.exportSaleInvReportNew(search,servletRequest,servletResponse);
            //lotInvReportService.exportSaleInvReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "获取订单流水报表（分页）", notes = "获取订单流水报表（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/OrderBlotter", method = RequestMethod.GET)
    public PagerInfo<List<OrderBlotterReportReponse>> searchOrderBlotReport(
            OrderBlotterReportSearchRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return orderBlotterReportService.searchOrderBlotReport(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出订单流水报表", notes = "导出订单流水报表")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportOrderBlotter", method = RequestMethod.GET)
    public void exportOrderBlotter(
            OrderBlotterReportSearchRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            orderBlotterReportService.exportOrderBlotReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "查询条码信息（分页）", notes = "查询条码信息（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/GoodsSn", method = RequestMethod.GET)
    public PagerInfo<List<GoodsSnReportReponse>>  searchGoodsSnReport(
            GoodsSnReportSearchRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return goodsSnReportService.searchGoodsSnReport(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出条码查询报表", notes = "导出条码查询报表")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportGoodsSn", method = RequestMethod.GET)
    public void exportGoodsSnReport(
            GoodsSnReportSearchRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            goodsSnReportService.exportGoodsSnReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "获取物料峰值报表（分页）", notes = "获取物料峰值报表（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/SkuPeakReport", method = RequestMethod.GET)
    public PagerInfo<List<PeakReportResponse>> searchSkuPeakReport(
            PeakReportRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return materialPeakService.searchSkuPeakReport(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出物料峰值报表", notes = "导出物料峰值报表")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportSkuPeakReport", method = RequestMethod.GET)
    public void exportSkuPeakReport(
            PeakReportRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            materialPeakService.exportSkuPeakReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "获取仓库峰值报表（分页）", notes = "获取仓库峰值报表（分页）")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/WhsPeakReport", method = RequestMethod.GET)
    public PagerInfo<List<PeakReportResponse>> searchWhsPeakReport(
            PeakReportRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
        try {
            return warehousePeakService.searchWhsPeakReport(search,pager);
        } catch (Exception ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "导出仓库峰值报表", notes = "导出仓库峰值报表")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @RequestMapping(value = REQUEST_MODEL + "/ExportWhsPeakReport", method = RequestMethod.GET)
    public void exportWhsPeakReport(
            PeakReportRequest search,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception{
        try {
            warehousePeakService.exportWhsPeakReport(search,servletRequest,servletResponse);
        } catch (Exception e) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

}
